<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/1/16
 * Time: 10:38
 */

namespace app\controller\phone;


use think\facade\View;

class Base
{
    protected $user;
    public function __construct()
    {
        global $user;
        session_start();
        if (empty($_SESSION)) {
            header('Location:/mobile/login');
            die;
        }
        if(empty($_SESSION['username'])) {
            header('Location:/mobile/login');
            die;
        }
        $user = $this->user = \app\model\index\User::where('username',$_SESSION['username'])->find();
        View::assign('user_message',$user);
    }

    protected function view($view = 'index', array $data = []){
        View::assign($data);
        return View::fetch($view);
    }

    protected function msg($data = [],string $msg = '成功',int $code = 200,int $http_code = 200){
        return json(['code' => $code,'msg' => $msg,'data' => $data],$http_code);
    }

    protected function fail($msg = 'fail',$code = 400,$http_code = 200){
        return json(['code' => $code,'msg' => $msg,'data' => (object)[]],$http_code);
    }
}